package com.ruoyi.project.dataanalysis.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dataanalysis.entity.*;
import com.ruoyi.project.dataanalysis.entity.Params;
import com.ruoyi.project.dataanalysis.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author 范莹莹
 * @version 1.0
 */
@Controller
@CrossOrigin
public class AnalysisController  extends BaseController {
    @Autowired
    AnalysisService analysisService;
    private String prefix = "dataanalysis";
    private Model model;

    //种植作物分析
    @GetMapping("/dataanalysis/crop")
    public String dataAnalysis_qd()
    {
        return prefix+"/analysis_crop";
    }
    //种植地域分析
    @GetMapping("/dataanalysis/analysis5")
    public String dataAnalysis_analysis5()
    {
        return prefix+"/analysis5";
    }
    //作物名称分析
    @GetMapping("/dataanalysis/analysis6")
    public String dataAnalysis_analysis6()
    {
        return prefix+"/analysis6";
    }

    @PostMapping("/dataanalysis/crop/list")
    @ResponseBody
    public  TableDataInfo  list(CropQL cropQL)
    {   startPage();
        cropQL.setStartTime(cropQL.getStartTime().replaceAll("-",""));
        cropQL.setEndTime(cropQL.getEndTime().replaceAll("-",""));
         List<CropQL> CropQLList= analysisService.selectAllcropByDate(cropQL);
        return getDataTable(CropQLList);
    }

    @RequestMapping(value="/dataanalysis/crop/json")
    @ResponseBody
    public  List<CropQL> ts_ql_json(CropQL cropQL)
    {
        cropQL.setStartTime(cropQL.getStartTime().replaceAll("-",""));
        cropQL.setEndTime(cropQL.getEndTime().replaceAll("-",""));
        List<CropQL> CropQLList= analysisService.selectAllcropByDate(cropQL);
        return   CropQLList;
    }
    //analysis5
    @RequestMapping(value="/dataanalysis/crop/cityname")
    @ResponseBody
    public  List<CropCityname> analysis5cityname(CropCityname cropCityname)
    {
        cropCityname.setStartTime(cropCityname.getStartTime().replaceAll("-",""));
        cropCityname.setEndTime(cropCityname.getEndTime().replaceAll("-",""));
        List<CropCityname> cropCitynameList= analysisService.selectCitynameByDate(cropCityname);
        return   cropCitynameList;
    }
    //analysis6
    @RequestMapping(value="/dataanalysis/crop/cropnamebytop")
    @ResponseBody
    public  List<CropNameByTop> analysis5namebytop(CropNameByTop cropNameByTop)
    {
        cropNameByTop.setStartTime(cropNameByTop.getStartTime().replaceAll("-",""));
        cropNameByTop.setEndTime(cropNameByTop.getEndTime().replaceAll("-",""));
        List<CropNameByTop> cropNameByTopList= analysisService.selectNameByTop(cropNameByTop);
        return   cropNameByTopList;
    }
    @RequestMapping(value="/dataanalysis/crop/cropnamebytoplist")
    @ResponseBody
    public  TableDataInfo cropnamebytoplist(CropNameByTop cropNameByTop)
    {   startPage();
        TableDataInfo rspData = new TableDataInfo();
        cropNameByTop.setStartTime(cropNameByTop.getStartTime().replaceAll("-",""));
        cropNameByTop.setEndTime(cropNameByTop.getEndTime().replaceAll("-",""));
        List<CropNameByTop> cropNameByTopList= analysisService.selectNameByTop(cropNameByTop);
        return getDataTable(cropNameByTopList);
}
/*
    @RequestMapping(value="/dataanalysis/qd/json")
    @ResponseBody
    public  List<ProblemsQd> ts_qd_json(Params params)
    {
        params.setStartTime(params.getStartTime().replaceAll("-",""));
        params.setEndTime(params.getEndTime().replaceAll("-",""));
        List<ProblemsQd> problemsQdList= problemsService.getProblemsQdList(params);
        return   problemsQdList;
    }

    @RequestMapping ("/problemDetails")
    public String problemDetials()
    {
        return "problemDetails";
    }


    @GetMapping("/dataanalysis/tsl")
    public String dataAnalysis_tsl()
    {
        return prefix+"/analysis_tsl";
    }

    @PostMapping("/dataanalysis/tsl/list")
    @ResponseBody
    public  TableDataInfo  list_tsl(Params params)
    {   startPage();
        ParamsConvert paramsConvert=new ParamsConvert();
        params=paramsConvert.ParamsConvertToMonth(params);
        List<ProblemsTsl> problemsTslList= problemsService.getTslList(params);
        return getDataTable(problemsTslList);
    }
    @Log(title = "投诉率分析", businessType = BusinessType.EXPORT)
    @RequiresPermissions("monitor:logininfor:export")
    @PostMapping("/dataanalysis/tsl/export")
    @ResponseBody
    public AjaxResult export_tsl(Params params)
    {
        ParamsConvert paramsConvert1=new ParamsConvert();
        params=paramsConvert1.ParamsConvertToMonth(params);
        List<ProblemsTsl> list = problemsService.getTslList(params);
        ExcelUtil<ProblemsTsl> util = new ExcelUtil<ProblemsTsl>(ProblemsTsl.class);
        return util.exportExcel(list, "投诉率");
    }


    @GetMapping("/dataanalysis/top5")
    public String dataAnalysis_top(Model model)
    {
        List<ProblemsDw> problemsDwList=problemsService.getDwList();
        model.addAttribute("problemsDwList",problemsDwList);
        return prefix+"/analysis_top";
    }

    @PostMapping("/dataanalysis/top5/list")
    @ResponseBody
    public  TableDataInfo  list_top(Params params)
    {   startPage();
        String s_time=params.getStartTime().replaceAll("-","");
        String e_time=params.getEndTime().replaceAll("-","");
        params.setStartTime(s_time);
        params.setEndTime(e_time);
        List<ProblemsTop> problemsTopList= problemsService.getTopList(params);
        return getDataTable(problemsTopList);
    }

    @PostMapping("/dataanalysis/top5/json")
    @ResponseBody
    public   List<ProblemsTop>  list_top_json(Params params,Model model)
    {   startPage();
        String s_time= params.getStartTime().replaceAll("-","");
        String e_time=params.getEndTime().replaceAll("-","");
        params.setStartTime(s_time);
        params.setEndTime(e_time);
        params.setDw(params.getDw());
        List<ProblemsTop> problemsTopList= problemsService.getTopList(params);
        return problemsTopList;
    }

    @GetMapping("/dataanalysis/top5/details")
    public String TopDetails(@RequestParam String param,Model model)
    {
        //mmap.put("operLog", operLogService.selectOperLogById(operId));
        //String a=param;
        Map<String,Object> map=new HashMap<>();
        model.addAttribute("dw",param.split(",")[0]);
        model.addAttribute("fl",param.split(",")[1]);
        return "/dataanalysis/details";
    }

    @PostMapping("/dataanalysis/top5/details/list")
    @ResponseBody
    public TableDataInfo TopDetailsList(Params params)
    {
        startPage();
        List<ProblemsDetails> problemsDetailsList= problemsService.getTopDetailList(params);
        return getDataTable(problemsDetailsList);
    }

    @Log(title = "TOP5问题明细", businessType = BusinessType.EXPORT)
    @RequiresPermissions("monitor:logininfor:export")
    @PostMapping("/dataanalysis/top5/details/export")
    @ResponseBody
    public AjaxResult export_top_detail(Params params)
    {
        List<ProblemsDetails> list = problemsService.getTopDetailList(params);
        ExcelUtil<ProblemsDetails> util = new ExcelUtil<ProblemsDetails>(ProblemsDetails.class);
        return util.exportExcel(list, "TOP明细");
    }



    @GetMapping("/dataanalysis/alldetails")
    public String dataAnalysis_alldetails(Model model)
    {
        List<ProblemsDw> problemsDwList=problemsService.getDwList();
        model.addAttribute("problemsDwList",problemsDwList);
        return prefix+"/analysis_alldetails";
    }

    @PostMapping("/dataanalysis/alldetails/list")
    @ResponseBody
    public TableDataInfo AllDetailsList(Params params)
    {
        startPage();
        String s_time=params.getStartTime().replaceAll("-","");
        String e_time=params.getEndTime().replaceAll("-","");
        params.setStartTime(s_time);
        params.setEndTime(e_time);
        List<ProblemsDetails> problemsAllDetailsList= problemsService.getAllDetailList(params);
        return getDataTable(problemsAllDetailsList);
    }

    @Log(title = "全量明细", businessType = BusinessType.EXPORT)
    @RequiresPermissions("monitor:logininfor:export")
    @PostMapping("/dataanalysis/alldetails/export")
    @ResponseBody
    public AjaxResult export_all_detail(Params params)
    {   String s_time=params.getStartTime().replaceAll("-","");
        String e_time=params.getEndTime().replaceAll("-","");
        params.setStartTime(s_time);
        params.setEndTime(e_time);
        List<ProblemsDetails> list = problemsService.getAllDetailList(params);
        ExcelUtil<ProblemsDetails> util = new ExcelUtil<ProblemsDetails>(ProblemsDetails.class);
        return util.exportExcel(list, "投诉全量明细");
    }

    @GetMapping("/dataanalysis/alldetails/slqk")
    public String slqk(@RequestParam String trade_id,Model model)
    {
        List<ProblemsDetails> list = problemsService.selectSlqkByTradeId(trade_id);
        for (int i=0;i<list.size();i++)
        {
            model.addAttribute("trade_id",list.get(i).getTrade_id());
            model.addAttribute("slnr",list.get(i).getSlnr());
            model.addAttribute("cljg",list.get(i).getCljg());
        }

        return "/dataanalysis/analysis_slqk";
    }

    @PostMapping("/dataanalysis/heatmap/json")
    @ResponseBody
    public List<ProblemsZB> dataAnalysis_heatmap(Params params)
    {
        List<ProblemsZB> problemsZbList= problemsService.selectTxzlZb(params);
        return problemsZbList;
    }

    @GetMapping("/dataanalysis/problems")
    public String problems()
    {
        return prefix+"/data_cj";
    }

    @PostMapping("/dataanalysis/problems/dataCj")
    @ResponseBody
    public TableDataInfo dataCj(Params params)
    {   startPage();
        List<Problems> problemsList= getProblemsData.getHttp(params);

        PageInfo<Problems> problemsPageInfo=new PageInfo<>();
        problemsPageInfo.setList(problemsList);
        return getDataTable(problemsList);
    }
    @GetMapping("/dataanalysis/mapdd")
    public String mapdd()
    {
        return prefix+"/map_dd";
    }

    @PostMapping("/dataanalysis/mapdd/insert")
    @ResponseBody
    public String  mapdd_insert(Params_dd params)
    {
        String i="1111";
        return i;
    }*/

}
